package com.ruoyi.keep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.Result;
import com.ruoyi.keep.domain.CommonUsers;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.Teacher;
import com.ruoyi.keep.service.ITeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练管理Controller
 * 
 * @author xjl
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/keep/teacher")
public class TeacherController extends BaseController {
    @Autowired
    private ITeacherService teacherService;

    /**
     * 查询教练管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(Teacher teacher) {
        startPage();
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        return getDataTable(list);
    }

    /**
     * 导出教练管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:export')")
    @Log(title = "教练管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Teacher teacher) {
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        ExcelUtil<Teacher> util = new ExcelUtil<Teacher>(Teacher.class);
        util.exportExcel(response, list, "教练管理数据");
    }

    /**
     * 获取教练管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teacherService.selectTeacherById(id));
    }

    /**
     * 新增教练管理
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:add')")
    @Log(title = "教练管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Teacher teacher) {
        return toAjax(teacherService.insertTeacher(teacher));
    }

    /**
     * 修改教练管理
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:edit')")
    @Log(title = "教练管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Teacher teacher) {
        return toAjax(teacherService.updateTeacher(teacher));
    }

    /**
     * 删除教练管理
     */
    @PreAuthorize("@ss.hasPermi('keep:teacher:remove')")
    @Log(title = "教练管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teacherService.deleteTeacherByIds(ids));
    }

    @GetMapping("/teacherGym/{id}")
    public Result findCard(@PathVariable("id") Long id) {
        List<Teacher> list = teacherService.selectGymByTeacherId(id);
        return Result.success(list);
    }


    @GetMapping("/allGym")
    public Result findGym(Teacher teacher){
        startPage();
        List<Teacher> list = teacherService.selectAllGym(teacher);
        return Result.success(list);
    }

    @GetMapping("/teacherByVenues/{id}")
    public Result findTeacherByVenuseId(@PathVariable("id") Long id) {
        List<Teacher> list = teacherService.selectTeacherByVenueId(id);

        return Result.success(list);
    }
}
